local skel = fk.CreateSkill {
  name = "emo__baoranzy",
  tags = {Skill.Compulsory},
}

skel:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  prompt = function (self, player, selected_cards, selected_targets)
    if #selected_targets == 2 then
      return "#emo__baoranzy2"
    end
    return "#emo__baoranzy"
  end,
  target_tip = function (self, player, to, selected, _, card, selectable, extra_data)
    if table.contains(selected, to) then
      if #selected == 3 then
        return "@@emo__baoranzy1"
      elseif #selected == 2 then
        return to == selected[1] and "@@emo__baoranzy2" or "@@emo__baoranzy1"
      else
        return "@@emo__baoranzy3"
      end
    end
  end,
  target_filter = function (self, player, to, selected)
    return #selected < 3 and to:getMark("@emo__leihuo") > 0
  end,
  feasible = function (self, player, selected)
    if #selected == 3 then return true end
    if #selected == 2 and selected[1]:getMark("@emo__leihuo") < 2 then return false end
    local n = 0
    for _, p in ipairs(selected) do
      n = n + p:getMark("@emo__leihuo")
    end
    return n >= 3
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local tos = effect.tos
    local list = {}
    for _, to in ipairs(tos) do
      list[to] = (#tos == 1 and 3 or 1)
      if #tos == 2 and to == tos[1] then
        list[to] = 2
      end
    end
    local to_add = {}
    for to, num in pairs(list) do
      room:removePlayerMark(to, "@emo__leihuo", num)
      table.insertIfNeed(to_add, to)
    end
    for _, to in ipairs(to_add) do
      room:addPlayerMark(to, "@emo__baoranzy-turn")
    end
    local cid = table.find(room.draw_pile, function (id)
      return Fk:getCardById(id).is_damage_card
    end) or table.find(room.discard_pile, function (id)
      return Fk:getCardById(id).is_damage_card
    end)
    if cid then
      room:obtainCard(player, cid, false, fk.ReasonJustMove, player, skel.name, "@@emo__baoranzy-inhand")
    end
  end,
})

skel:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and not card:isVirtual() and card:getMark("@@emo__baoranzy-inhand") ~= 0
  end,
})

-- 无次数限制=不计入次数
skel:addEffect(fk.PreCardUse, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card:getMark("@@emo__baoranzy-inhand") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
})

skel:addEffect(fk.DamageInflicted, {
  mute = true,
  is_delay_effect = true,
  priority = 1.001, -- 修改伤害值比防止伤害先结算
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__baoranzy-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data:changeDamage(player:getMark("@emo__baoranzy-turn"))
  end,
})


Fk:loadTranslationTable{
  ["emo__baoranzy"] = "爆燃灼印",
  [":emo__baoranzy"] = "出牌阶段限一次，你可以移除场上3枚雷火标记，获得一张无次数限制的伤害牌，令被移除标记的角色本回合受到伤害+1。",

  ["#emo__baoranzy"] = "移去3枚雷火标记，获得伤害牌，被移去标记角色受伤+1",
  ["#emo__baoranzy2"] = "第一个选择的角色移去2枚雷火标记，第二个移去1枚",
  ["@@emo__baoranzy1"] = "移去1枚",
  ["@@emo__baoranzy2"] = "移去2枚",
  ["@@emo__baoranzy3"] = "移去3枚",
  ["@@emo__baoranzy-inhand"] = "爆燃",
  ["@emo__baoranzy-turn"] = "<font color='red'>灼印</font>",

  ["$emo__baoranzy1"] = "雷火之心爆燃模式，开启！",
}


return skel
